package cn.wenhaha.lazy;

/**
 * @ClassName: LazyFour
 * @description: TODO  第四种懒加载方式，使用内部类，是线程安全的
 * @author: wyndem
 * @date: 2019/5/13 12:52
 * @Version: 1.0
 **/
public  class LazyFour {

    private static boolean initialized=false;

    /**
     * description: 防止反射来创建对象
     * @Author wyndem
     * @Date 2019/5/13 13:02
     * @Param []
     * @return
     **/
    private LazyFour() {

        synchronized (LazyFour.class){
            if (initialized == false){
                initialized=!initialized;
            }else{
                throw  new RuntimeException("该对象只能创建一次");
            }
        }


    }

    public  static LazyFour getInstance(){
        return  LazyHolder.LAZY;
    }



    //默认不加载
    private static class LazyHolder{
        private static final LazyFour LAZY = new LazyFour();
    }


}
